package util;

import model.User;

public class SessionManager {
    private static User currentUser;

    public static void setCurrentUser(User user) {
        currentUser = user;
    }

    public static User getCurrentUser() {
        return currentUser;
    }

    public static boolean isLoggedIn() {
        return currentUser != null;
    }

    public static boolean isAdmin() {
        return isLoggedIn() && "admin".equals(currentUser.getRole());
    }

    public static boolean isManager() {
        return isLoggedIn() && ("admin".equals(currentUser.getRole()) || "manager".equals(currentUser.getRole()));
    }

    public static void clear() {
        currentUser = null;
    }

    public static String getCurrentUsername() {
        return isLoggedIn() ? currentUser.getUsername() : "未登录";
    }

    public static String getCurrentRole() {
        return isLoggedIn() ? currentUser.getRole() : "未登录";
    }
}